import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userInfo: {
      username: window.localStorage.getItem('userInfo' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('userInfo' || '[]')).username,
      power: window.localStorage.getItem('userInfo' || '[]') == null ? '' : JSON.parse(window.localStorage.getItem('userInfo' || '[]')).power,
    },
  },
  mutations: {
    login (state, user) {
      state.userInfo = user;
      window.localStorage.setItem('userInfo', JSON.stringify(user))
    }
  },
  getters:{
    userInfo:(state)=>{
     return state.userInfo
    }
  }
})
